import { IFormProps, size, formItemLayout, getUploadResult, productPage, getImages, getFileList } from '../../utils/common';
import React from 'react';
import { Modal, Form, Input, Select, Upload, Checkbox, InputNumber } from 'antd';
import * as api from '../../api/api';
import { FormComponentProps } from 'antd/lib/form';
import Uploads from '../Uploads';
const TextArea = Input.TextArea;
export interface IItemSkuEditProps extends FormComponentProps {
    visible: boolean,
    itemSku?: api.SingleUserMallItemsVOItemSkuVO,
    itemSkuCategories: Array<api.SingleUserMallItemsVOItemSkuCategoryVO>,
    onSave: (any) => void,
    onCancel: () => void,
}
class ItemSkuEdit extends React.PureComponent<IItemSkuEditProps, any>{
    constructor(props) {
        super(props);
    }

    state = {
        fileList: [],
    }

    ok = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, form) => {
            if (!err) {
                this.props.onSave(form);
            }
        });
    }

    reset = () => {
        this.props.form.resetFields();
    }

    cancel = () => {
        this.props.onCancel();
    }

    imageChange = (fileList) => {
        this.setState({ fileList });
    }

    render(): JSX.Element {
        const { getFieldDecorator } = this.props.form;
        const { itemSku, itemSkuCategories } = this.props;
        return (
            <Modal
                title='商品规格明细信息'
                visible={this.props.visible}
                onOk={this.ok}
                onCancel={this.cancel}
                maskClosable={true}
            >
                <Form>
                    <Form.Item label="规格" {...formItemLayout}>
                        {getFieldDecorator('itemSkuCategoryId', {
                            rules: [
                                {
                                    required: true,
                                    message: '请选择规格'
                                }
                            ],
                            initialValue: itemSku && itemSku.itemSkuCategoryId
                        })(<Select>
                            {
                                itemSkuCategories.map((i) => {
                                    return <Select.Option value={i.id}>{i.name}</Select.Option>
                                })
                            }
                        </Select>)}
                    </Form.Item>
                    <Form.Item label="规格明细" {...formItemLayout}>
                        {getFieldDecorator('sku', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入规格明细'
                                }
                            ],
                            initialValue: itemSku && itemSku.sku
                        })(<Input size={size}
                            placeholder="请输入规格明细" />)}
                    </Form.Item>
                </Form>
            </Modal>)
    }
}

export default Form.create()(ItemSkuEdit);